Skip to content

Conversation

@rmolinamir
Copy link
Contributor

Summary

This PR adds database query indexes to improve performance for common query patterns in the application, particularly for journal entries and pages.

Changes

Database Schema Updates

Journal Entry Schema:

  • Added journal_entry_user_id_date_desc_index
  • Indexes on user_id and date (descending order)
  • Improves performance for journal timeline queries

Page Schema:

  • Updated page_user_id_updated_at_desc_index
  • Fixed syntax from using btree to proper .on() with .desc()
  • Indexes on user_id and updated_at (descending order)
  • Improves performance for page pagination queries

Performance Impact

These indexes will significantly improve query performance for:

  • Journal timeline queries - filtering by user and sorting by date
  • Page pagination queries - filtering by user and sorting by updated_at
  • User-specific data operations - any queries that filter by user_id
  • Infinite scroll pagination - faster cursor-based pagination
  • Sidebar page loading - improved performance for the pages sidebar

Technical Details

  • Uses Drizzle ORM proper index syntax with .on() and .desc()
  • Indexes are optimized for the most common query patterns
  • No breaking changes to existing functionality
  • Database migration will be required to apply these indexes

Testing

  • Schema changes compile without errors
  • Index syntax is correct for Drizzle ORM
  • No breaking changes to existing queries
  • Ready for database migration

- Add journal_entry_user_id_date_desc_index for efficient journal entry queries by user and date
- Update page_user_id_updated_at_desc_index to use proper descending order syntax
- These indexes will improve performance for:
  - Journal timeline queries (user_id + date desc)
  - Page pagination queries (user_id + updated_at desc)
  - User-specific data filtering and sorting operations
@rmolinamir rmolinamir merged commit f3fd9ea into main Sep 27, 2025
0 of 3 checks passed
@rmolinamir rmolinamir deleted the feat/database-query-indexes branch September 27, 2025 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants